﻿using System;
using System.Collections.Generic;


namespace Voize
{
    internal class CRandom
    {


        internal CRandom()
        {
			m_PlayedSongs = new List<int>();
        }



		private List<int> m_PlayedSongs;



        internal int GetRandomPlaylistRow(int maximum)
        {
			int row;

			row = this.RandomSong(maximum);

			foreach (int song in m_PlayedSongs)
				if (song == row)
				{
					while (song == row)
					{
						if (this.m_PlayedSongs.Count != maximum)
						{
							row = this.RandomSong(maximum);
							if (song != row)
								break;
						}
						else
						{
							this.m_PlayedSongs.Clear();
							break;						
						}
					}
					break;
				}

			m_PlayedSongs.Add(row);

			return row;
        }



		private int RandomSong(int maximum)
		{
			int row;
			int max = maximum;
			Random rnd = new Random();

			row = rnd.Next(0, max);
			
			return row;

		}



    }
}
